<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class RunErrand extends Model
{
    use HasDateTimeFormatter;

    protected $fillable = ['user_id', 'nick_name', 'mobile', 'id_number', 'school_id', 'faculty_id', 'specialty', 'id_card_front', 'id_card_reverse_side', 'status', 'fail_reason', 'blacklists'];
    protected $appends = ['id_card_front_url', 'id_card_reverse_side_url'];

    public function school()
    {
        return $this->belongsTo(School::class);
    }

    public function faculty()
    {
        return $this->belongsTo(Faculty::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function idCardFrontUrl(): Attribute
    {
        return Attribute::make(get: fn() => $this->id_card_front ? Storage::disk('oss')->url($this->id_card_front) : null);
    }

    public function idCardReverseSideUrl(): Attribute
    {
        return Attribute::make(get: fn() => $this->id_card_reverse_side ? Storage::disk('oss')->url($this->id_card_reverse_side) : null);
    }


}
